// pages/doctorDetails/doctorDetails.js
var request = require("../../utils/request.js")
const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        doctorInfo: "",
        visitTimeList: "",
        day:"", //预约日期 2022/12/12
        date: "", // 预约日期 //几号
        time: "", // 预约时间
        hourList: [],
        cid:'',
        infoName:""
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.toastDialog = this.selectComponent("#toastDialog"); //此处id和页面的 wxml中的id一致
        //console.log(options)
        this.doctorDetails(options.pid)
        //console.log(new Date().getDate())
        this.setData({
            date: new Date().getDate(),
            cid:options.cid,
            infoName:options.infoName
        })
        wx.showShareMenu({ menus: ['shareAppMessage', 'shareTimeline']})
    },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage (res) {
    return {
      title: '迪佳极视',
      path: 'pages/index/index',
      // imageUrl:'这个是显示的图片，不写就默认当前页面的截图',
      success: function (shareTickets) {
        console.info(shareTickets + '成功');
        // 转发成功
      },
      fail: function (res) {
        console.log(res + '失败');
        // 转发失败
      },
      complete:function(res){
        // 不管成功失败都会执行
      }
    }
  },
    //选择日期
    chooseDate: function (e) {
        console.log(e);
        this.setData({
            time:'',
            hourList: e.currentTarget.dataset.item.hourList,
            date: e.currentTarget.dataset.item.date,
            day: e.currentTarget.dataset.item.day
        })
    },
    //选择就诊时间
    chooseTime:function(e){
        console.log(e)
        if(e.currentTarget.dataset.check){
            this.setData({
                time:e.currentTarget.dataset.time
            })
            console.log(this.data.time)
        }
       
    },
    doctorDetails: function (e) {
        let that = this
        that.toastDialog.showDialog({
            code: 'loading',
            message: '加载中',
            timeout: false
        }); //loading 加载框
        request.postData('xcx/clinicDoctorInfo', {
            "cdId": e
        }, function (res) {
            // success
            console.log(res)
            that.toastDialog.hideDialog(); //关闭loading提示框
            if (res.code == '0') {
                //console.log(res.info.visitTimeList.length);
                //这块是干啥的？？？
                for (var i = 0; i < 7; i++) {
                    res.info.visitTimeList[i].date = res.info.visitTimeList[i].day.substring(8, 10)
                    res.info.visitTimeList[i].day = res.info.visitTimeList[i].day.substring(0, 7)
                }
                //跟接口返回来的数据也没变化呀？？
                console.log(res.info.visitTimeList)
                that.setData({
                    "doctorInfo": res.info,
                    "visitTimeList": res.info.visitTimeList,
                    "hourList": res.info.visitTimeList[0].hourList,
                    "day":res.info.visitTimeList[0].day,
                    "date":res.info.visitTimeList[0].date
                })
                console.log(that.data.hourList)
            } else {
                that.toastDialog.showDialog({
                    code: res.code,
                    message: res.message,
                    timeout: true
                });
            }

        }, function (res) {
            // error
            that.toastDialog.showDialog({
                code: res.code,
                message: res.message,
                timeout: true
            });
        });
    },
    //快速预约
    confirmAppoinment:function(){
      wx.navigateTo({
        url: '../ReservationForm/ReservationForm?time='+this.data.time+'&day='+this.data.day+'/'+this.data.date+'&cid='+this.data.cid+'&name='+this.data.infoName+'&doctorName='+this.data.doctorInfo.name+'&dateType=doctor',
      })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    }
})